﻿<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
				<el-form ref="elForm" :model="dataForm" size="medium" label-width="115px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="24" >
						<el-form-item label="合同编号" prop="contractId">
							<el-input v-model="dataForm.contractId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="项目名称" prop="proName">
							<el-select v-model="dataForm.proName" placeholder="请选择" clearable required :style='{"width":"100%"}' filterable >
								<el-option v-for="(item, index) in proNameOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="合同类型" prop="contractType">
							<el-select v-model="dataForm.contractType" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in contractTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="合同甲方" prop="partyA">
							<el-input v-model="dataForm.partyA" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="合同乙方" prop="partyB">
							<el-input v-model="dataForm.partyB" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="合同阶段" prop="stage">
							<el-select v-model="dataForm.stage" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in stageOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="合同金额" prop="amount">
							<el-input-number v-model="dataForm.amount" placeholder="数字文本" required :step="100" >
							</el-input-number>元
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="签约时间" prop="signingTime">
							<el-date-picker v-model="dataForm.signingTime" placeholder="请选择" clearable required :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="我方签约人" prop="desPersonName">
							<user-select v-model="dataForm.desPersonName" placeholder="请选择" required >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="履约时间" prop="startTime">
							<el-date-picker v-model="dataForm.startTime" placeholder="请选择" clearable required :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="结束时间" prop="endTime">
							<el-date-picker v-model="dataForm.endTime" placeholder="请选择" clearable required :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="对方签约人" prop="lastHander">
							<el-input v-model="dataForm.lastHander" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="对方联系电话" prop="lastHanderMobile">
							<el-input v-model="dataForm.lastHanderMobile" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="合同说明" prop="remark">
							<el-input v-model="dataForm.remark" placeholder="请输入" required show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="合同附件" prop="appendix">
							<JNPF-UploadFz v-model="dataForm.appendix" required :fileSize="20" sizeUnit="MB" :limit="9" buttonText="点击上传" >
							</JNPF-UploadFz>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="中标通知书" prop="spare2">
							<JNPF-UploadFz v-model="dataForm.spare2" :fileSize="20" sizeUnit="MB" :limit="9" buttonText="点击上传" >
							</JNPF-UploadFz>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建人" prop="creater">
							<el-input v-model="dataForm.creater" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建时间" prop="createTime">
							<el-input v-model="dataForm.createTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="最后修改人" prop="modifyer">
							<el-input v-model="dataForm.modifyer" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改时间" prop="modifyTime">
							<el-input v-model="dataForm.modifyTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>
	</transition>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		components: {},
		props: [],
		data() {
			return {
				loading: false,
				visible: false,
				isDetail: false,
				dataForm: {
					contractId:undefined,
					proName:undefined,
					contractType:undefined,
					partyA:undefined,
					partyB:undefined,
					stage:undefined,
					amount:0,
					signingTime:undefined,
					desPersonName:undefined,
					startTime:undefined,
					endTime:undefined,
					lastHander:undefined,
					lastHanderMobile:undefined,
					remark:undefined,
					appendix:[],
					spare2:[],
					creater:undefined,
					createTime:undefined,
					modifyer:undefined,
					modifyTime:undefined,
				},
				rules: {
					proName:[
						{
							required:true,
							message:'请输入项目名称',
							trigger:'change'
						},
					],
					contractType:[
						{
							required:true,
							message:'请输入合同类型',
							trigger:'change'
						},
					],
					partyA:[
						{
							required:true,
							message:'请输入合同甲方',
							trigger:'blur'
						},
					],
					partyB:[
						{
							required:true,
							message:'请输入合同乙方',
							trigger:'blur'
						},
					],
					stage:[
						{
							required:true,
							message:'请输入合同阶段',
							trigger:'change'
						},
					],
					amount:[
						{
							required:true,
							message:'请输入合同金额',
							trigger:["blur","change"]
						},
					],
					signingTime:[
						{
							required:true,
							message:'请输入签约时间',
							trigger:'change'
						},
					],
					desPersonName:[
						{
							required:true,
							message:'请输入我方签约人',
							trigger:'change'
						},
					],
					startTime:[
						{
							required:true,
							message:'请输入履约时间',
							trigger:'change'
						},
					],
					endTime:[
						{
							required:true,
							message:'请输入结束时间',
							trigger:'change'
						},
					],
					lastHander:[
						{
							required:true,
							message:'请输入对方签约人',
							trigger:'blur'
						},
					],
					lastHanderMobile:[
						{
							required:true,
							message:'请输入对方联系电话',
							trigger:'blur'
						},
						{
							pattern:/^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
							message:'请输入正确的联系方式',
							trigger:'blur'
						},
					],
					remark:[
						{
							required:true,
							message:'请输入合同说明',
							trigger:'blur'
						},
					],
					appendix:[
						{
							required:true,
							message:'请输入合同附件',
							trigger:'click'
						},
					],
				},
				proNameOptions : [],
				contractTypeOptions : [],
				stageOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getproNameOptions();
			this.getcontractTypeOptions();
			this.getstageOptions();
		},
		mounted() {
        },
		methods: {
			getproNameOptions(){
				previewDataInterface('195045591036724485').then(res => {
					this.proNameOptions = res.data
				});
			},
			getcontractTypeOptions(){
				getDictionaryDataSelector('10a0f6e141174fafa23ed8310a2ada76').then(res => {
					this.contractTypeOptions = res.data.list
				});
			},
			getstageOptions(){
				getDictionaryDataSelector('f8b2198685b34ab6b6fef03cdfca9286').then(res => {
					this.stageOptions = res.data.list
				});
			},
			goBack() {
                this.$emit('refresh')
            },
			init(id, isDetail) {
				this.dataForm.id = id || 0;
                this.visible = true;
                this.isDetail = isDetail || false;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/SubDev/ZyOaProContract/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						})
					}
				})
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/SubDev/ZyOaProContract`,
                                method: 'post',
                                data: this.dataForm,
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false,
                                            this.$emit('refresh', true)
                                    }
                                })
                            })
                        } else {
                            request({
                                url: '/api/SubDev/ZyOaProContract/' + this.dataForm.id,
                                method: 'PUT',
                                data: this.dataForm
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refresh', true)
                                    }
                                })
                            })
                        }
                    }
                })
			},
		}
	}
</script>
